using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Scenario_Editor.WR2TerrainLoader
{
    class Sound
    {
        float   PositionX;
        float   PositionY;
        float   PositionZ;
        ObjectName soundName;
        short   volume;
        short   tempo;
        short   radius;
        EnumSoundType soundType;
        short   unknown;
        short   delay; // (value : 10 = sec)
        byte[]  unknown2 = new byte[12];

        internal Scenario_Editor.Exporter.WR2Traffic.SpeedBlock SpeedBlock
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        public static Sound FromStream(BinaryReader br)
        {
            Sound sound = new Sound();
            sound.PositionX = br.ReadSingle();
            sound.PositionY = br.ReadSingle();
            sound.PositionZ = br.ReadSingle();
            sound.soundName = ObjectName.LoadFromStreamByte(br);
            sound.volume = br.ReadInt16();
            sound.tempo = br.ReadInt16();
            sound.radius = br.ReadInt16();
            sound.soundType = (EnumSoundType)br.ReadUInt16();
            sound.unknown = br.ReadInt16();
            sound.delay = br.ReadInt16(); // (value : 10 = sec)
            sound.unknown2 = br.ReadBytes(12);

            return sound;
        }


        /// <summary>
        /// Saves the specified bw.
        /// </summary>
        /// <param name="bw">The bw.</param>
        internal void Save(BinaryWriter bw)
        {


            bw.Write(this.PositionX);//sound.PositionX = br.ReadSingle();
            bw.Write(this.PositionY);//sound.PositionY = br.ReadSingle();
            bw.Write(this.PositionZ); //sound.PositionZ = br.ReadSingle();
            this.soundName.Save(bw);//sound.soundName = ObjectName.LoadFromStreamByte(br);
            bw.Write(this.volume);//sound.volume = br.ReadInt16();
            bw.Write(this.tempo); //sound.tempo = br.ReadInt16();
            bw.Write(this.radius);//sound.radius = br.ReadInt16();
            bw.Write((short)this.soundType); //sound.soundType = (EnumSoundType)br.ReadUInt16();
            bw.Write(this.unknown);//sound.unknown = br.ReadInt16();
            bw.Write(this.delay);//sound.delay = br.ReadInt16(); // (value : 10 = sec)
            bw.Write(unknown2);//sound.unknown2 = br.ReadBytes(12);
        }
    }
}
